package com.hd.crdao.activity;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hd.crdao.R;
import com.hd.crdao.config.Constants;
import com.hd.crdao.utils.ALog;
import com.hd.crdao.wrapper.GlideImageUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *
 *@author Programming
 *@date 2017/7/14 0014
 */
public class SwitchImageActivity extends Activity {

    private List<String> mPaths;
    public PagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switchimage);
        initView();
    }

    private void initView() {
        ViewPager switchImage = (ViewPager) findViewById(R.id.switchimage);
        String[] imagepath =  getIntent().getStringArrayExtra("imagepath");
        mPaths = new ArrayList<>();
        if(imagepath!=null){
            Collections.addAll(mPaths, imagepath);
        }
        pagerAdapter = new PagerAdapter() {
            @Override
            public int getCount() {
                return mPaths.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView((View) object);
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                ImageView imageView = new ImageView(container.getContext());
                String path = mPaths.get(position);
                //   imageView.setImageBitmap(BitmapFactory.decodeFile(Constants.IMAGEURL+path));
                ALog.d(path);
                GlideImageUtils.loadImage(Constants.IMAGEURL + path,R.drawable.loading_small,imageView);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                container.addView(imageView);
                return imageView;
            }
        };

        switchImage.setAdapter(pagerAdapter);

    }



}
